package zheezes.protocol.impl.gd;

import java.util.Arrays;

import org.apache.log4j.PropertyConfigurator;
import org.springframework.context.support.AbstractApplicationContext;

import zheezes.eisp.util.SpringUtil;
import zheezes.socket.PostOffice;
import zheezes.util.Log4jUtil;
import zheezes.util.Util;


/**
 * @author chen han
 * this frame is designed for test buffer overflow
 */
public class DeathFrame extends GdFrame {
	private int size = 1024;

	@Override
	public int getData(byte[] buf, int offset) {
		Arrays.fill(buf, offset, offset + size, (byte) 0x00);
		return size;
	}

	@Override
	public int setData(byte[] buf, int offset, int max) {
		return 0;
	}

	@Override
	public int sizeOfData() {
		return size;
	}
	
	public static void main(String[] args) {
		PropertyConfigurator.configure("log4j.properties");
		Log4jUtil.setLogFile("collect.log");
		AbstractApplicationContext context = SpringUtil.getApplicationContext();
		PostOffice postOffice = (PostOffice) context.getBean("postOffice");
		DeathFrame frame = new DeathFrame();
		frame.setRtua(new GdConAddr("82419988"));
		postOffice.send(frame);
		// manager.run();
		// in the destroy function, only one code, close();
		Util.msleep(5 * 1000);
		context.destroy();
	}
}
